import re
import chardet as chardet
import requests

final_url = "https://api.bilibili.com/x/v1/dm/list.so?oid=437729555"
final_res = requests.get(final_url)
final_res.encoding = chardet.detect(final_res.content)['encoding']
final_res = final_res.text
pattern = re.compile('<d.*?>(.*?)</d>')
data = pattern.findall(final_res)

with open("弹幕.txt", mode="w", encoding="utf-8") as f:
    for i in data:
        f.write(i)
        f.write("\n")